/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package anton.menu;

import anton.dinner.DinnerEntity;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author johan
 */
@ManagedBean(name="viewMenu")
@SessionScoped

public class ViewMenu {
  
    //managed property handles my sql search in Dinner table
   @ManagedProperty(value="#{listDinners}")
   
   private ListDinner listDinner;
   //Managed property
   @ManagedProperty(value="#{listMenu}")
    
   private ListDinnerMenu listMenu;
    
   private String sqlDinnerMenu;
   private String sqlMenu;
   private int fineMenuId;
   private String fineMenuName;
   private String dinnerType;
   private  ArrayList<DinnerEntity> dinnerList;
   

   
   /*------------------------------------------------------------------------*/
   // setters and getters
   
    public int getFineMenuId() {
        return fineMenuId;
    }

    public void setFineMenuId(int fineMenuId) {
        this.fineMenuId = fineMenuId;
    }
   

    public ListDinner getListDinner() {
        return listDinner;
    }

    public void setListDinner(ListDinner listDinner) {
        this.listDinner = listDinner;
    }

    public ListDinnerMenu getListMenu() {
        return listMenu;
    }

    public void setListMenu(ListDinnerMenu listMenu) {
        this.listMenu = listMenu;
    }

    
    public String getFineMenuName() {
        return fineMenuName;
    }

    public void setFineMenuName(String fineMenuName) {
        this.fineMenuName = fineMenuName;
    }
      
   
    
   //method used to initialize list of menu names and return list
   public ArrayList<DinnerMenu> getMenuList() throws SQLException
   {      
        
       sqlMenu="select finemenu_Id, finemenu_name from FineMenu";
       
       listMenu.setSql(sqlMenu);
       
       ArrayList<DinnerMenu> temp=listMenu.getMenu();
       
       return temp;
   }
   
   
   
   //method returns a list containing dinners of category apetizer
  public  ArrayList<DinnerEntity>  getApetizer() throws SQLException
        {
        
        dinnerType ="apetizer";
        ArrayList<DinnerEntity> temp= getMenu();
        
        return temp;
        
        }
    
  // method returns a list containing of category main course
    public  ArrayList<DinnerEntity>  getMainCourse() throws SQLException
        {
        
        dinnerType ="Main Course";
        ArrayList<DinnerEntity> temp= getMenu();
        
        return temp;
        
        }
    
    
    // method returns a list containing of category dessert
    public  ArrayList<DinnerEntity>  getDessert() throws SQLException
        {
        
        dinnerType ="dessert";
        ArrayList<DinnerEntity> temp= getMenu();
        
        return temp;
        
        }
   
    // prepares the menu by setting the Menu name
     public String prepareMenu() throws SQLException
    {
        // iterates list to get entry with matching fineMenuId collection change to map?
        for(DinnerMenu dinnerMenu:listMenu.getMenu()) 
        {   
            
            
           if( dinnerMenu.getFineMenuId()==fineMenuId)
           { 
               
               this.fineMenuName= dinnerMenu.getFineMenuName();
           
              break;
           }
        
        
        }
    
    return "/admin/dinnermenu/viewmenu?faces-redirect=true";
    }
    
    
   //method used to get a list of dinners 
    public ArrayList<DinnerEntity> getMenu() throws SQLException
            
            
            
    {   // sql query that select dinner items based on their menuId and type
        sqlDinnerMenu="select Dinner.dinner_name, dinner_description, dinner_price ,dinner_type from FineMenu,"
        +"FineDinnerMenu,Dinner where Dinner.Dinner_name= FineDinnerMenu.Dinner_name and "    
        +"FineDinnerMenu.finemenu_ID = FineMenu.finemenu_ID and FineMenu.finemenu_ID="+fineMenuId+" and dinner_type ='"+dinnerType+"';";
         
        listDinner.setSql(sqlDinnerMenu);
        
        dinnerList=listDinner.getMenu();
        
    return dinnerList;
    }
    
    
    
}
